<template>
  <el-dialog :append-to-body="true" :close-on-click-modal="false" :before-close="cancel" :visible.sync="dialog" title="编辑" width="500px">
    <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
      <el-form-item label="账户ID" >
        <el-input v-model="form.id" style="width: 370px;" readonly/>
      </el-form-item>
      <el-form-item label="OpenId" >
        <el-input v-model="form.openid" style="width: 370px;" readonly/>
      </el-form-item>
      <el-form-item label="余额" >
        <el-input-number :precision="2" :step="0.1" v-model="form.balance" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="累计金额" >
        <el-input-number :precision="2" :step="0.1" v-model="form.cumulative" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="赠送金额" >
        <el-input-number :precision="2" :step="0.1" v-model="form.bonus" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="积分" >
        <el-input-number v-model="form.integral" style="width: 370px;"/>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="text" @click="cancel">取消</el-button>
      <el-button :loading="loading" type="primary" @click="doEdit">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { postRequest } from '@/api/identity'
export default {

  data() {
    return {
      loading: false, dialog: false,
      form: {
        id: 0,
        openid: '',
        balance: 0,
        cumulative: 0,
        integral: 0,
        bonus: 0
      },
      rules: {
      }
    }
  },
  methods: {
    cancel() {
      this.resetForm()
    },
    doEdit() {
      console.log(this.form)
      postRequest('/pc/identityAccount', this.form).then(res => {
        this.resetForm()
        this.$notify({
          title: '修改成功',
          type: 'success',
          duration: 2500
        })
        this.loading = false
        this.$parent.initMethod()
      }).catch(err => {
        this.loading = false
        console.log(err)
      })
    },
    resetForm() {
      this.dialog = false
      this.$refs['form'].resetFields()
      this.form = {
        id: 0,
        openid: '',
        balance: 0,
        cumulative: 0,
        integral: 0,
        bonus: 0
      }
    }
  }
}
</script>

<style scoped>

</style>
